package chapter.fourth.item20;
//标签类
public class Figure {
	enum Shape{RECTANGLE,CIRCLE};
	//标签域
	final Shape shape;
	//矩形的域
	double length;
	double width;
	//圆形的域
	double radius;
	
	Figure(double radius){
		shape = Shape.CIRCLE;
		this.radius = radius;
	}
	
	Figure(double length,double width){
		shape = Shape.RECTANGLE;
		this.length = length;
		this.width = width;
	}
	
	double area(){
		switch(shape){
		case RECTANGLE:
			return length*width;
		case CIRCLE:
			return Math.PI*(radius*radius);
		default:
			throw new AssertionError();
		}
	}
}
